package leetcode.数组;

public class 丢失的数字268 {
    public static int missingNumber(int[] nums) {
        int n = nums.length;
        int sum = sum(n);
        int sum2 = 0;
        for (int i = 0; i < nums.length; i++) {
            sum2 += nums[i];
        }
        return sum-sum2;
    }

    public static int sum(int n){
        int sum = 0;
        for (int i = 0; i <= n; i++) {
            sum+=i;
        }
        return sum;
    }

    public static void main(String[] args) {
        int[] nums = {3,0,1};
        missingNumber(nums);
    }

}
